package com.tj.test.sys.service.impl;

import com.tj.test.sys.dao.QuestionpaperMapper;
import com.tj.test.sys.po.Questionpaper;
import com.tj.test.sys.service.IQuestionpaperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class QuestionpaperService implements IQuestionpaperService {
    @Autowired
    private QuestionpaperMapper mapper;

    @Override
    //查询所有试卷答考题表信息
    public List<Questionpaper> selectAllQuestionpaper() {
        List<Questionpaper> list=new ArrayList<>();
        if (!mapper.selectAllQuestionpaper().isEmpty()){
            list=mapper.selectAllQuestionpaper();
        }
        return list;
    }

    @Override
    //插入试卷考题表信息
    public int insertQuestionpaper(Questionpaper questionpaper) {
        int temp=0;
        /* 业务判断
         * （1）名称不能重复
         * （2）增加之前先查询*/
           try{
        temp=mapper.selectQuestionpaperById(questionpaper);
        if (temp<1){
            temp=mapper.insertQuestionpaper(questionpaper);
        }else{
            return temp;
        }
        }catch (Exception e){
            return -2;
        }
        return temp;
    }

    @Override
    //删除试卷考题表信息
    public int deleteQuestionpaper( Questionpaper questionpaper) {
        int temp=0;
        try{
            temp=mapper.selectQuestionpaperById(questionpaper);
            if (temp>0){
                temp=mapper.deleteQuestionpaper(questionpaper);
            }else{
                return -2;
            }
        }catch (Exception e){
            return -1;
        }
        return temp;
    }

    @Override
    //修改试卷考题表信息
    public int updateQuestionpaper(Questionpaper questionpaper) {
        int temp=0;
        try{
            temp=mapper.selectQuestionpaperById(questionpaper);
            if (temp<1){
                temp=mapper.updateQuestionpaper(questionpaper);
            }else{
                return temp;
            }
        }catch (Exception e){
            System.out.println(e.getStackTrace());
            return -1;
        }
        return temp;
    }
}
